﻿using PdfSharp.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageToPdf
{
    public static class ConvertImageToXImage
    {
        public static XImage ToXImage(this Image image)
        {
            // 将 System.Drawing.Image 转换为内存流
            using (var ms = new MemoryStream())
            {
                // 将图片保存到内存流中
                image.Save(ms, image.RawFormat);

                // 从内存流创建 XImage
                return XImage.FromStream(ms);
            }
        }
    }
}
